import win32com.client 

def print_trade_record(portf, path):

	xApp = win32com.client.Dispatch("Excel.Application")
	xBook = xApp.Workbooks.Add()
	xSht = xBook.Worksheets(1)
	
	xSht.Cells(1, 1).Value = 'Trade Date'
	xSht.Cells(1, 2).Value = 'Asset Type'
	xSht.Cells(1, 3).Value = 'Ticker'
	xSht.Cells(1, 4).Value = 'Quantity'
	
	row = 2
	for elem in portf.activity_list():
	
		asset_type = elem[1].type_name()
		xSht.Cells(row, 1).Value = elem[0]
		xSht.Cells(row, 2).Value = asset_type
		
		if asset_type == 'CASH':
			xSht.Cells(row, 3).Value = elem[1].currency()
		else:
			xSht.Cells(row, 3).Value = elem[1].ticker()
			
		xSht.Cells(row, 4).Value = elem[2]
		
		row += 1
	
	xSht.Name = portf.name() + ' - Trade Records'
	xBook.SaveAs(path)
	xBook.Close()
	del xApp
	
def print_nav(perf, path):

	xApp = win32com.client.Dispatch("Excel.Application")
	xBook = xApp.Workbooks.Add()
	xSht = xBook.Worksheets(1)
	
	xSht.Cells(1, 1).Value = 'Date'
	xSht.Cells(1, 2).Value = 'Asset Value'
	
	row = 2
	for elem in perf.nav_series():
	
		xSht.Cells(row, 1).Value = elem[0]
		xSht.Cells(row, 2).Value = elem[1]
		
		row += 1
	
	xSht.Name = perf.portfolio().name() + ' - Asset Value'
	xBook.SaveAs(path)
	xBook.Close()
	del xApp
